﻿@using Covenant.Models.Grunts
@using Covenant.Models.Listeners
@model ImplantTemplate
@{
    Layout = "_ImplantTemplateLayout";
    ViewData["Title"] = "ImplantTemplates";
    List<ListenerType> ListenerTypes = ViewBag.ListenerTypes;
    IEnumerable<SelectListItem> listenerTypeSelectList = ListenerTypes.Select(LT =>
    {
        return new SelectListItem { Text = LT.Name, Value = LT.Id.ToString(), Selected = Model.CompatibleListenerTypes.Select(CLT => CLT.Id).Contains(LT.Id) };
    });
}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap pb-2 mb-3">
    <h1 class="h2">Implant Template: <span id="implant-name" class="text-primary">@Html.DisplayFor(model => model.Name)</span></h1>
</div>

<form asp-action="Edit">
    <div asp-validation-summary="All"></div>
    <input asp-for="Id" value="@Model.Id" type="hidden">
    <div class="form-row">
        <div class="form-group col-md-4">
            <label asp-for="Name"></label>
            <input asp-for="Name" value="@Model.Name" class="form-control">
        </div>
        <div class="form-group col-md-8">
            <label asp-for="Description"></label>
            <input asp-for="Description" value="@Model.Description" class="form-control">
        </div>
    </div>
    <div class="form-row">
        <div class="form-group col-md-3">
            <label asp-for="Language"></label>
            <select asp-for="Language" asp-items="Html.GetEnumSelectList<ImplantLanguage>()" class="form-control"></select>
        </div>
        <div class="form-group col-md-3">
            <label asp-for="CommType"></label>
            <select asp-for="CommType" asp-items="Html.GetEnumSelectList<CommunicationType>()" class="form-control"></select>
        </div>
        <div class="form-group col-md-3">
            <label asp-for="ImplantDirection"></label>
            <select asp-for="ImplantDirection" asp-items="Html.GetEnumSelectList<ImplantDirection>()" class="form-control"></select>
        </div>
        <div class="form-group col-md-3">
            <label asp-for="CompatibleListenerTypes"></label>
            <select asp-for="CompatibleListenerTypes" class="selectpicker show-menu-arrow" multiple data-dropup-auto="false" data-width="auto" data-live-search="true" data-selected-text-format="count > 2">
                @foreach (var listenertype in listenerTypeSelectList)
                {
                    if (listenertype.Selected)
                    {
                        <option selected value="@listenertype.Value">@listenertype.Text</option>
                    }
                    else
                    {
                        <option value="@listenertype.Value">@listenertype.Text</option>
                    }
                }
            </select>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group col-md-12">
            <label asp-for="StagerCode"></label>
            <textarea asp-for="StagerCode" value="@Model.StagerCode" rows="5" class="form-control border-1"></textarea>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group col-md-12">
            <label asp-for="ExecutorCode"></label>
            <textarea asp-for="ExecutorCode" value="@Model.ExecutorCode" rows="5" class="form-control border-1"></textarea>
        </div>
    </div>
    <button type="submit" class="btn btn-primary"><span data-feather="edit"></span> Edit</button>
</form>

@section Scripts {
    <script type="text/javascript">$(document).ready(function () {
            var editor1 = CodeMirror.fromTextArea(document.getElementById("StagerCode"), {
                lineNumbers: true,
                mode: "text/x-csharp"
            });
            var editor2 = CodeMirror.fromTextArea(document.getElementById("ExecutorCode"), {
                lineNumbers: true,
                mode: "text/x-csharp"
            });
        });</script>
}
